public class Solution {
    public int reverse(int x) {

        int num=0;
        int a=0;

        while(x!=0){
            //判断下一步反转之后是否已经超过范围
            //若超过，则直接返回0
            if(num<Integer.MIN_VALUE/10||num>Integer.MAX_VALUE/10){
                return 0;
            }
            a=x%10;
            x/=10;

            num=num*10+a;

        }
        return num;
    }
}